
from openpyxl.styles import Font, Alignment
from openpyxl import load_workbook
import os

filename = os.getcwd() + os.sep + 'test2.xlsx'
workbook = load_workbook(filename)
sheet = workbook.active
cell = sheet['A1']
#设置字体央视
font = Font(name='微软雅黑', size=12,bold=True,italic=True,color='FF0000')
cell.font = font
workbook.save(filename)

#设置对其样式
#Alignment = Alignment(horizontal='center',vertical='center')
cell = sheet['B2']
alignment = Alignment(horizontal='center',vertical='center',text_rotation=45,wrap_text=True)
cell.alignment = alignment
workbook.save(filename)

